{template "common/header"}

<ul class="nav nav-tabs">
	<li {if $op == 'list'}class="active"{/if}>
	<a href="{php echo $this->createWebUrl('user',array('op'=>'list'))}" >用户列表</a>
	</li>
	{if $op == 'mystudy'}
	<li {if $op == 'mystudy'}class="active"{/if}>
	<a href="javascript:void(0)" >已学习课程</a>
	</li>
	{/if}
</ul>
{if $op == 'list'}
<div style="margin-bottom: 25px">
	<div class="list-group">
		<p class="list-group-item " style="background-color: #D9EDF7">按条件搜索</p>
		<div active="list-group-item" style="border:1px solid #cecece">
			<form action="./index.php" method="get" class="form-horizontal">
				<input type="hidden" name="c" value="site">
				<input type="hidden" name="a" value="entry">
				<input type="hidden" name="m" value="goouc_class">
				<input type="hidden" name="do" value="user">

				<div class="form-group col-sm-8" style="margin-top:25px" >
					<label  class="col-sm-4 control-label" style="padding-right: 11px">用户姓名/手机号/微信昵称：</label>
					<div class="col-sm-8">
						<input type="text" name="keyword" value="{$keyword}" class="form-control" style="width:98%"/>
					</div>
				</div>
				<div class="form-group col-sm-3" style="margin-top:25px" >
					<button class="btn btn-default" style="margin-left:140px"><i class="fa fa-search"></i> 搜索</button>
				</div>
				<div style="clear:both"></div>
			</form>
		</div>
	</div>
    <div class="list-group">
        <p class="list-group-item " style="background-color: #D9EDF7">用户列表</p>
        <div active="list-group-item" style="border:1px solid #D9EDF7">
			<a href="{php echo $this->createWebUrl('user',array('op'=>'import'))}"  class="btn btn-success" data-toggle="modal"  style="float:right;margin: 15px"><span onclick="">赠送兑换币</span></a>
	        		<table class="table table-bordered table-hover" style="margin-top:25px;width:98%;text-align:center;table-layout: fixed;" align="center">
	        			<tr>
	        				<th style="width: 35px;text-align:center;">序号</th>
	        				<th style="width: 35px;text-align:center;">头像</th>
							<th style="width: 60px;text-align:center;">昵称</th>
	        				<th style="width: 40px;text-align:center;">姓名</th>
	        				<th style="width: 30px;text-align:center;">性别</th>
	        				{if $_W['uid'] != 29}
	        				<th style="width: 60px;text-align:center;">手机号</th>
	        				{/if}
	        				<th style="width: 40px;text-align:center;">城市</th>
	        				<th style="width: 50px;text-align:center;">学校</th>
	        				<th style="width: 35px;text-align:center;">兑换币</th>
	        				<th style="width: 50px;text-align:center;">周学习时长</th>
	        				<th style="width: 50px;text-align:center;">月学习时长</th>
	        				<th style="width: 50px;text-align:center;">注册时间</th>
							<th style="width: 40px;text-align:center;">状态</th>
							<th style="width: 70px;text-align:center;">已学习课程</th>
	        			</tr>
	        			{loop $userlist $row}
	        			<tr>

	        				<td>{php echo $total--;}</td>
	        				<td><img src="{$row['headimg']}" alt="" style="width:40px"></td>
							<td>{$row['nickname']}</td>
	        				<td>{$row['name']}</td>
	        				<td>{if $row['sex'] == 1}男{elseif $row['sex'] == 2}女{/if}</td>
	        				{if $_W['uid'] != 29}
	        				<td>{$row['phone']}</td>
	        				{/if}
	        				<td>{$row['city1']}</td>
	        				<td>{$row['school']}</td>
	        				<td>{$row['card']}</td>
	        				<td>{php echo round($row['looktime']/60,2)}分钟</td>
	        				<td>{php echo round($row['looktimem']/60,2)}分钟</td>
	        				<td>{php echo date('Y-m-d H:i:s',$row['createtime'])}</td>
							<td ><button value="{$row['id']}" {if $row['status'] == 0}class="btn btn-danger status"{elseif $row['status'] == 1}class="btn btn-info status"{/if} >{if $row['status'] == 0}禁用{elseif $row['status'] == 1}正常{/if}</button></td>
							<td><button class="btn btn-success"><a style="text-decoration:none; color:#fff;" href="{php echo $this->createWebUrl('user',array('id'=>$row['id'],'op'=>'mystudy'))}">已学习课程</a></button></td>
	        			</tr>
	        			{/loop}
	        		</table>
	        		{$page}
	        	</div>
	        </div>
</div>
<script type="text/javascript">
	$('.status').click(function(){
		var a = $(this);
		var id = $(this).val();
		var url = "{php echo $this->createWebUrl('user')}";
		var val = $(this).html();
		// console.log(val);
		$.ajax({
			type:'post',
			url:url,
			data:{id:id,val:val,op:'list'},
			dataType:'JSON',
			success:function(res){
				// console.log(res);
				if(res > 0){
					if(val == '正常'){
						a.html('禁用');
						a.removeClass('btn-info');
						a.addClass("btn-danger");
					}else if(val == '禁用'){
						a.html('正常');
						a.removeClass("btn btn-danger");
						a.addClass("btn btn-info");
					}
				}
			}
		});
	});
</script>
{elseif $op == 'mystudy'}
<table class="table table-bordered table-hover" style="margin-top:25px;width:98%" align="center">
	<tr>
		<th style="text-align: center;width: 20%;">课程/章节编号</th>
		<th style="text-align: center">课程/章节名称</th>
		<th style="text-align: center">章节类型</th>
	</tr>
	{loop $array_less $v}
	<tr>
		<td style="text-align: center">课程编号{$v['id']}</td>
		<td>
			<a onclick="return sonlist({$v['id']})">{$v['title']}&nbsp;&nbsp;<i class="fa fa-plus"></i></a>
		</td>
		<td>{if $v['paytype'] == 2}免费课程{elseif $v['paytype'] == 3}兑换币{elseif $v['paytype'] == 4}付费{/if}</td>
	</tr>
	{if !empty($v['son'])}
	{loop $v['son'] $vv}
	<tr class="son{$v['id']}" style="display:none">
		<td style="text-align: right">章节编号{$vv['id']}</td>
		<td>{$vv['title']} </td>
		<td style="text-align: left;color:orangered"></td>
	</tr>
	{/loop}
	{/if}
	{/loop}
</table>
<script type="text/javascript">
    function sonlist(id){
        var display = $('.son'+id).css('display');
        console.log($(this));
        if(display == 'none'){
            $(".son"+id).css({'display':'table-row'});
        }else{
            $(".son"+id).css({'display':'none'});
        }
    }
</script>
{/if}

{template "common/footer"}